package cn.cnsuh.controller.web.servlet;


import cn.cnsuh.domain.User;
import cn.cnsuh.service.UserService;
import cn.cnsuh.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Magic
 * @create 2020-05-23 16:45
 */
@WebServlet("/findAllServlet")
public class FindAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        UserService service = new UserServiceImpl();
        List<User> users = service.findAll();


        //2.将list存入request域
        request.setAttribute("users", users);
        request.getRequestDispatcher("/cmd.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
